package operation.freeMarker;

import freemarker.template.TemplateException;
import operation.freeMarker.util.FreemarkerUtil;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class TestUtil {
    /**
     * 模板路径
     */
    static String ftlPath = "D:\\workspace\\abandon-me\\server\\src\\main\\java\\operation\\freeMarker\\ftl";

    /**
     * 模板生成路径
     */
    static String toPath = "D:\\workspace\\abandon-me\\server\\src\\main\\java\\operation\\freeMarker\\";

    /**
     * 开始生成模板（原生）
     * @param args
     * @throws IOException
     * @throws TemplateException
     */
//    public static void main(String[] args) throws IOException, TemplateException {
//        Configuration cfg = new Configuration(Configuration.VERSION_2_3_29);
//        cfg.setDirectoryForTemplateLoading(new File(ftlPath));
//        cfg.setObjectWrapper(new DefaultObjectWrapper(Configuration.VERSION_2_3_29));
//        Template temp = cfg.getTemplate("test.ftl");
//        Map root = new HashMap();
//        root.put("actionName", "helloWorld");
//
//        FileWriter fw = new FileWriter(toPath + "export.java");
//        BufferedWriter bw = new BufferedWriter(fw);
//        temp.process(null, bw);
//        bw.flush();
//        fw.close();
//    }

    /**
     * 生成代模板测试
     * @param args
     * @throws IOException
     * @throws TemplateException
     */
    public static void main(String[] args) throws IOException, TemplateException {
//        FreemarkerUtil.initConfig(2, "test.ftl");
        Map<String,Object> map = new HashMap<>();
        map.put("Domain", "Hermiwwwwt");
        map.put("domain", "hermit");
//        FreemarkerUtil.generator(toPath + "Test.java", map);
        autoMake(map);
    }

    /**
     * 生成代码测试
     */
    public static void autoMake(Map<String, Object> map) throws IOException, TemplateException {
        FreemarkerUtil.initConfig(2, "test.ftl");
        FreemarkerUtil.generator(toPath + "Test.java", map);
    }

}
